home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / exampl14.spr < prev    next >
Text File  |  1989-11-11  |  2KB  |  68 lines

  1. /* exampl14.spr */
  2. /* A graph searching program. 
  3.  
  4.    Our notion of graph can be thought of as just a set of towns
  5.    and connecting rail segments, each of which has a given length.
  6.  
  7.    The predicate "segment" has three arguments: 
  8.    1) A town at one end of a rail segment.
  9.    2) A town at other end of rail segment.
  10.    3) The distance of the road between them.
  11.    
  12.    The main predicate is "journey". Try (exampl14).
  13.  */
  14.  
  15. /* The figures are off the top of my head (they are guestimates) */
  16. (segment paris orleans 100)
  17. (segment orleans blois 50)
  18. (segment blois tours 50)
  19. (segment orleans bourges 150)
  20. (segment paris chartres 100)
  21. (segment chartres le_mans 80)
  22. (segment le_mans angers 80)
  23. (segment le_mans tours 75)
  24. (segment angers nantes 100)
  25. (segment paris amiens 120)
  26.  
  27.  
  28. ((link A B Length)
  29.      (segment A B Length)
  30. )
  31. ((link A B Length)
  32.      (segment B A Length)
  33. )
  34.  
  35.  
  36. /*            predicate journey 
  37.   Departure, Arrival are the knowns and Itinerary and Distance
  38.    are the unknowns : 
  39.  */
  40. ((journey Departure Arrival Itinerary Distance)
  41.      (journey1 Departure Arrival () Itinerary Distance)
  42. )
  43.  
  44.  
  45. /* The third argument of journey1 is used for the bookeeping purpose
  46.    of checking that we dont go round in circles : It is the list
  47.    of towns visited "so far".
  48.  */
  49. ((journey1 A B _ (A B) D)
  50.     (link A B D)
  51. )
  52. ((journey1 A B L (A | R) D)
  53.  (link A V D1)
  54.  (diff V B)
  55.  (not (member V L))
  56.  (journey1 V B (A|L) R D2)
  57.  (iplus D1 D2 D)
  58. )
  59.  
  60. /* try (exampl14) */
  61. ((exampl14)
  62.  (journey amiens nantes I D)
  63.  (writes "For a journey from Amiens to Nantes you can try:")
  64.  (nl)
  65.  (display I)(nl)
  66.  (writes "distance = ")(display D)(writes " kms.")(nl)
  67. )
  68.